<?php
/**
 * (exporter)
 */
namespace App\Exporter\Products;

use App\Models\Product\ProductAmazonSku;
use App\Models\Product\ProductClassify;
use App\Models\Product\ProductSku;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class AmazonSkuExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '亚马逊产品.csv';

    protected $headings = ['SKU','组合','名称','季节性','品类','账号','国家','平台SKU','销售员',
        '条码类型','条码','PartNo.','平台PartNo.','母ASIN','子ASIN','FNSKU','泛欧模式','泛欧国家计数','创建人','创建时间','启用'];

    public function map($model) : array
    {
        return [
            $model->sku->psku_code ?? '',
            ProductSku::$_isMix[$model->sku->is_mix ?? 0],
            $model->sku->psku_cn,
            ProductClassify::$_season[$model->skuClassify->season ?? 3],
            $model->skuClassify->title ?? '',
            $model->account->account ?? '',
            $model->country->country ?? '',
            $model->seller_sku,
            User::getUsernameById($model->seller_id),
            ProductAmazonSku::$_barcodeType[$model->barcode_type],
            $model->barcode,
            $model->sku->part_number ?? '',
            $model->amazon_part_number,
            $model->parent_asin,
            $model->child_asin,
            $model->fnsku,
            ProductAmazonSku::$_fanEu[$model->fan_eu],
            $model->times == 0 || $model->times == 4 ? '正常' : $model->times,
            User::getUsernameById($model->cuser_id),
            $model->created_at,
            ProductAmazonSku::$_status[$model->status],
        ];
    }

}
